
"""
datefile = open("date.txt", mode="r")
lines = datefile.readlines()
print(lines)
datefile.close()
"""
import datetime
import sys
import os

def current_timestamp() :
    """
        返回当前时间戳的字符串, 带3位毫秒
    """
    return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]


DATES = {}
def checkforshutdown(date = datetime.datetime.now().strftime("%Y-%m-%d")) -> bool:
    """
    检查今天该不该关机
    """
    global DATES
    if os.path.exists("date.txt") :
        if len(DATES) == 0 :
            datefile = open("date.txt", mode="r")
            lines = datefile.readlines()
            for line in lines :
                line = line.replace("\n", "")
                ss = line.split("\t")
                d = ss[0]
                ok = int(ss[1])
                DATES[d] = ok
            datefile.close()
        today = date
        if today in DATES.keys() :
            print(today,DATES[today])
            if DATES[today] == 1 :
                return True
            else :
                return False
        else :
            return False
    return False

    
print(checkforshutdown("2024-09-12"))